home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Text Processing / Skim < prev    next >
Internet Message Format  |  1993-12-30  |  3KB

  1. From: pottier@clipper.ens.fr (Francois Pottier)
  2. Subject: Submission : skim 
  3. Date: Fri, 16 Jul 93 19:37:52 MET DST 
  4.  
  5.  
  6. This an enhancement to the original "skim" program, written by
  7. Craig Nevill-Manning. This program helps you browse through an
  8. info-mac digest (such as those posted on comp.sys.mac.digest).
  9. For each new file submission, it asks you whether you want to
  10. download the file or not. Then it creates a script named
  11. "download". Running this script connects automatically to the
  12. info-mac ftp site (sumex) and does all the job for you.
  13.  
  14. This allows to you to download programs at night, by typing
  15. something like :
  16.   /bin/nohup at 0200am download
  17.  
  18. Attention : this program is designed for UNIX boxes, NOT Macs.]
  19.  
  20. To the archive maintainer : I have Craig's authorization to publish
  21. this small hack, so everything's ok.
  22.  
  23. The C code (skim.c) follows :
  24.  
  25. /* To compile this program, first modify the #defines. You have to choose the
  26.    local directory to be used and to set your e-mail address.
  27.  
  28.    Then compile with cc -o skim skim.c -lcurses -ltermcap 
  29.  
  30.  
  31.    Original skim program by : 
  32.  
  33.    Craig Nevill-Manning,            e-mail: cgn@waikato.ac.nz
  34.    Department of Computer Science,  phone:  +64 7 838 4021 (work)
  35.    University of Waikato,                   +64 7 838 4232 (home)
  36.    Private Bag 3105,                      
  37.    Hamilton,
  38.    New Zealand. 
  39.  
  40.    Enhanced (added automatic script creation) by : 
  41.  
  42.    Francois Pottier                 e-mail: pottier@dmi.ens.fr
  43. */
  44.  
  45.  
  46. #define localDirectory   "~/Mac/NEW"
  47. #define siteName         "sumex-aim.stanford.edu"
  48. #define emailAddress     "pottier@dmi.ens.fr"
  49.  
  50. #include <stdio.h>
  51. #include <curses.h>
  52.  
  53. FILE *download;
  54.  
  55. main(argc, argv)
  56. int argc;
  57. char **argv;
  58. {
  59.   int i;
  60.  
  61.   initscr();
  62.   cbreak();
  63.   
  64.  
  65.   download = fopen("download", "w");
  66.   fprintf(download, "%s\n\n%s%s\n%s%s%s\n%s%s\n%s\n",
  67.                     "#!/bin/csh -f",
  68.                     "cd ", localDirectory,
  69.                     "ftp -n ", siteName, " << EOF",
  70.                     "user anonymous ", emailAddress,
  71.                     "ascii");
  72.  
  73.   for (i = 1; i < argc; i ++)
  74.     skim(argv[i]);
  75.  
  76.   fprintf(download, "EOF\n");
  77.   fclose(download);
  78.  
  79.   (void) chmod ("download", 493);    /* octal 755, rwxr-xr-x */
  80.  
  81.   nocbreak();
  82.   endwin();
  83. }
  84.  
  85. skim(filename)
  86. char *filename;
  87. {
  88.   FILE *f;
  89.   char s[1000], name[1000], nameOnly[1000];
  90.   int ch, line;
  91.  
  92.   f = fopen(filename, "r");
  93.  
  94.   if (f) {
  95.     
  96.  
  97.     while (!feof(f)) {
  98.       do {
  99.     fgets(s, 1000, f);
  100.       } while (strncmp(s, "Subject: [*]", 12) != 0 && !feof(f));
  101.  
  102.       line = 0;
  103.  
  104.       name[0] = 0;
  105.  
  106.  
  107.       clear();
  108.       refresh();
  109.  
  110.       puts(filename);
  111.       while (!feof(f)) {
  112.     if (line ++ < LINES - 4)
  113.       printf("%s", s);
  114.     fgets(s, 1000, f);
  115.     if (strncmp(s, "[Archived as", 12) == 0) {
  116.       strcpy(name, &s[13]);
  117.       break;
  118.     }
  119.       }
  120.  
  121.       printf("%s", s);
  122.       
  123.  
  124.       if (name[0]) {
  125.     printf("Get this? (y/n)");
  126.  
  127.     do
  128.       ch = getchar();
  129.     while (ch != 'y' && ch != 'n' && ch != 'q');
  130.  
  131.     if (ch == 'y') {
  132.       int i;
  133.  
  134.       for (i = strlen(name); i > 0 && name[i] != ';'; i --) ;
  135.       name[i] = 0;
  136.  
  137.           for (i = strlen(name); i > 0 && name[i] != '/'; i--) ;
  138.           strcpy(nameOnly, &name[i+1]);
  139.           name[i] = 0;
  140.  
  141.       fprintf(download, "cd %s\n", name);
  142.           fprintf(download, "get %s\n", nameOnly);
  143.     }
  144.     else if (ch == 'q') {
  145.       fclose(download);
  146.       nocbreak();
  147.       endwin();
  148.       exit(0);
  149.     }
  150.       }
  151.     }
  152.  
  153.     fclose(f);
  154.   }
  155. }
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.